/** @namespace app.model.AnchorData */
/** @namespace Service.this.model.AnchorData */
module.exports = app => {
  const {BIGINT, INTEGER, DATEONLY, BOOLEAN} = app.Sequelize;
  const AnchorData = app.model.define('anchor_data', {
    num_follower: {type: INTEGER.UNSIGNED, defaultValue: 0},//关注人数
    num_gift: {type: BIGINT.UNSIGNED, defaultValue: '0'},//礼物价值
    num_watch: {type: BIGINT.UNSIGNED, defaultValue: 0},//观看人气
    num_live: {type: INTEGER.UNSIGNED, defaultValue: 0},//当天直播时间，单位 分钟
    is_new_anchor: {type: BOOLEAN, defaultValue: false},//在当天是不是新的主播
    created_at: {type: DATEONLY, defaultValue: app.Sequelize.NOW},//创建日期
  }, {
    tableName: 'spider_anchor_data',
    indexes: [
      {//唯一
        unique: true,
        name: 'platform_anchor_date',
        fields: ['created_at', 'type_id', 'anchor_id'],
      },
    ],
  });
  AnchorData.associate = () => {
    //【主播数据】与【直播类型】绑定
    app.model.AnchorData.belongsTo(app.model.Type,
        {foreignKey: {name: 'type_id', allowNull: false}});
    app.model.Type.hasMany(app.model.AnchorData,
        {foreignKey: {name: 'type_id', allowNull: false}});

    //【主播数据】与【主播】绑定
    app.model.AnchorData.belongsTo(app.model.Anchor,
        {foreignKey: {name: 'anchor_id', allowNull: false}});
    app.model.Anchor.hasMany(app.model.AnchorData,
        {foreignKey: {name: 'anchor_id', allowNull: false}});
  };
  return AnchorData;
};